import {Injectable} from '@angular/core';
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {Storage} from '@ionic/storage';
import {AppConfig} from '../common/app-config.enum';

@Injectable({
  providedIn: 'root'
})
export class LogoutGuard implements CanActivate {

  constructor(private storage: Storage
  ) {
  }

  async canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot
  ): Promise<boolean> {
    // 获取用户信息
    const userInfo = await this.storage.get(AppConfig.USER_INFO);
    return !(userInfo && userInfo[AppConfig.USER_INFO_KEY]);
  }
}
